# Maintainer: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Contributor: Nathan Angelacos <nangel@alpinelinux.org>
pkgname=rmilter
pkgver=1.10.0
pkgrel=0
pkgdesc="Rspamd mail filter"
url="https://rspamd.com/rmilter"
arch="all"
license="BSD"
pkgusers="rmilter"
pkggroups="rmilter"
depends=""
depends_dev=""
makedepends="$depends_dev cmake bison flex bsd-compat-headers
	libressl-dev pcre-dev libmilter-dev opendkim-dev hiredis-dev
	glib-dev"
install="$pkgname.pre-install $pkgname-clamav.pre-install $pkgname-dkim.pre-install"
subpackages="$pkgname-clamav::noarch $pkgname-rspamd::noarch $pkgname-redis::noarch $pkgname-dkim::noarch"
source="$pkgname-$pkgver.tar.gz::https://github.com/vstakhov/$pkgname/archive/$pkgver.tar.gz
	$pkgname-clamav.conf
	$pkgname-rspamd.conf
	$pkgname-redis.conf
	$pkgname-dkim.conf
	$pkgname.confd
	$pkgname.initd
	$pkgname.conf
	config.patch
	config_dir.patch
	system_hiredis.patch
"
builddir="$srcdir"/$pkgname-$pkgver

build() {
	cd "$builddir"
	cmake CMakeLists.txt \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DRMILTER_USER=$pkgusers \
		-DRMILTER_GROUP=$pkggroups \
	|| return 1
	make || return 1
}

package() {
	cd "$builddir"
	make DESTDIR="$pkgdir" install || return 1
	install -Dm644 $pkgname.conf.sample "$pkgdir"/etc/$pkgname/$pkgname.conf.common
	install -Dm644 "$srcdir"/$pkgname.conf "$pkgdir"/etc/$pkgname/$pkgname.conf
	install -Dm755 "$srcdir"/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
	install -Dm644 "$srcdir"/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
	install -dm755 "$pkgdir"/etc/$pkgname/conf.d
}

clamav() {
	pkgdesc="$pkgdesc: enable virus scanning with local Clamav instance"
	depends="$pkgname clamav"
	install -Dm644 /dev/null "$subpkgdir"/etc/conf.d/$pkgname-rc_need@clamd
	install -Dm644 "$srcdir"/$pkgname-clamav.conf "$subpkgdir"/etc/$pkgname/conf.d/clamav.conf
}

rspamd() {
	pkgdesc="$pkgdesc: enable spam filtering with local Rspamd instance"
	depends="$pkgname rspamd"
	install -Dm644 /dev/null "$subpkgdir"/etc/conf.d/$pkgname-rc_need@rspamd
	install -Dm644 "$srcdir"/$pkgname-rspamd.conf "$subpkgdir"/etc/$pkgname/conf.d/rspamd.conf
}

redis() {
	pkgdesc="$pkgdesc: enable greylisting and limits with local Redis backend"
	depends="$pkgname redis"
	install -Dm644 /dev/null "$subpkgdir"/etc/conf.d/$pkgname-rc_need@redis
	install -Dm644 "$srcdir"/$pkgname-redis.conf "$subpkgdir"/etc/$pkgname/conf.d/redis.conf
}

dkim() {
	pkgdesc="$pkgdesc: enable DKIM"
	depends="$pkgname"
	install -dm750 -g mail "$subpkgdir"/etc/mail
	install -dm755 "$subpkgdir"/etc/mail/dkim
	install -Dm644 "$srcdir"/$pkgname-dkim.conf "$subpkgdir"/etc/$pkgname/conf.d/dkim.conf
}

md5sums="220d693636f9ec5606033d15816a2346  rmilter-1.10.0.tar.gz
ae0cd1a2b91e06c217d3883211ef57b8  rmilter-clamav.conf
bdbd10caee1958ce5f9b8b899accac9c  rmilter-rspamd.conf
690b8f76f40f1a16d3ca7b994c27b637  rmilter-redis.conf
33eafa022a0e918c7a1cf74a81654373  rmilter-dkim.conf
d37109f41764e89606d1e40c30c010de  rmilter.confd
098a8f376dab26291f3a5e3e775e14b5  rmilter.initd
a4a15e6c89caaecf7bbdae681cdf36a2  rmilter.conf
87da6d59c5ca17e760668ba878d83391  config.patch
e4f3e1ea90401b8d55e6a381af05b994  config_dir.patch
d1aded4ee98211bd5e644c63c77eab8b  system_hiredis.patch"
sha256sums="ea80563fa7636afed0b5fd9a29aa2300f15793ed85788e4ce69c187d341a7d54  rmilter-1.10.0.tar.gz
35f6eecbac988a4a2fdbb649fdf93aec5e77ded321aaa0521ddc9ef2ffe721e1  rmilter-clamav.conf
eae2a0867c3e258fa052f1ada5465cf3132da87028ac9ac1a829c3239382fa13  rmilter-rspamd.conf
9c265b9dc02b5e520d62228e9486d8bf96041f50da8f240ad352a5b189da8b27  rmilter-redis.conf
f7513ab4345d127d2a6ef34848bc68faea83e3f7cdc11f1da641e2934bb19dd9  rmilter-dkim.conf
fd7ac67f1c2d8bc03fee67f5fca4d0a12c562eaaab00a390e0f8e5230e6a5da4  rmilter.confd
d0cce00aa6780fabbba03d14ab4ffa914326ac48a085bcde4c12853f8c44037d  rmilter.initd
ee73f437d02ef343eb0c1aa6d2da5bfc502e4ee93fb9d9f3362dda2efe9e5a13  rmilter.conf
aada82ad61f3d33d285e163e054748159c378f4b7713814bf8ae94c6451bea1e  config.patch
1aa29ce0a638356d4ebd75757a2094f9db20ad3895867e3676d5ae1129352760  config_dir.patch
aa57dbf0e6244675989caec1a62ce969f044e0f0dc4f7bfee00e91ae19c58bc0  system_hiredis.patch"
sha512sums="bef62d6dd4190b9a28e751cc598d201f0f994a08def46ae68587d1cc956e7e209ae540d91241545dc4efd055b4bf2b95039f0e9649448e5506f17ec37240adf8  rmilter-1.10.0.tar.gz
e28357e8eab451cb972149b003db56e4386f17e137c3a690e90c4b161edd6eeb7da99b8f36cdf016f11161664b90825ee2f706ce70887c6d8b9c6a7b167770cd  rmilter-clamav.conf
15db17901e4fc53596860dadade29b656d0addb390a56a610d13caee6362c867215de0fb57071ba87f0b97620d076444ad22fd87a3c27b2ca709fc31d71ed19c  rmilter-rspamd.conf
f56f4295209483e2e2d0ecceeecdd8a73e547ba85bca6cf9c54f3a57a87b3ca1dfbb6dd062d54224840019cee47a062d8b9384b8b08a789b0ea46b947cb11ac2  rmilter-redis.conf
b558762c18fbcb0a50c787094d267fabae3d336ea665b126fccf1fc67284b38336ee4b9997e23091bc64e60a0302e3c5a3f659581b72dccc5da0d26c8e722f30  rmilter-dkim.conf
a8c91009662e1f4b4fd140df8187bc2b781aab167b71219ed63447da480f3b856bea00e48651f26104e5e53f096a84dc10f769067bc9c0e6e1d504a9fcef4fbd  rmilter.confd
010d6e8e83087212ef0fe0bebfcd9581e8205dcf2ddf3434f7b25b9e80959cd6f24a5ede3207f9a104b3d467a5649e365a78fa609a7d2bf361253c803bb1ab2c  rmilter.initd
1ab84f669bd05268816c2c454e939921102713f4ce9ef39ca695a21fc3410d915abecabd5b732022f945abfdf3d1e39ab13c8412c8de46420651a1b26e2374b3  rmilter.conf
2112a10358d7f00931a850f501db53481932badeee488afc8d8481c07bde8556449e2485c0fad5e5a0837fd921dc153a674e1c69fc1d055f6f10b89f2f061237  config.patch
6ac3a1d73e52c156b60cabaabceea6e01c7e5f2dce78a557ccce24127440a8fea713b2465ecdd29486c4283afb6dee723cbcb476f1789bcd3876dd6c6aa5ebd1  config_dir.patch
6913c39c3335ecaebd6413ea8d39630cf67bc5fba9a91609f1ea25f756702e1652d51429534a5223a7136a7424deaffd16c2a2fb8d32fa1a1f1f23b3b8fed87c  system_hiredis.patch"
